<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>添加或编辑界面</title>
    <link rel="stylesheet" type="text/css" href="${s.base}/lib/layui/css/layui.css"/>
    <link rel="stylesheet" type="text/css" href="${s.base}/css/base/index.css"/>
    <link rel="stylesheet" type="text/css" href="${s.base}/css/base/theme/theme.css"/>
    <style>
        .w440 {
            width: 440px !important;
        }
    </style>
</head>
<body>
<div class="page-content-wrap clearfix">
    <form class="layui-form" id="tool">
        <input type="hidden" name="applyId" value="${applyId}" />
        <div class="layui-tab">
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;标题：</label>
                        <div class="layui-input-inline w440">
                            <input type="text" name="title" value="${notice.title}" lay-verify="required" placeholder="请输入标题" autocomplete="off"
                                   class="layui-input" maxlength="200">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;内容：</label>
                        <div class="layui-input-inline w440">
                            <div class="layui-upload">
                                <textarea id="content" name="content" lay-verify="content" placeholder="请输入内容">${notice.content}</textarea>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;类型：</label>
                        <div class="layui-input-inline w440">
                            <select name="noticeType" id="noticeType" lay-verify="required"></select>
                        </div>
                    </div>
                    <div class="layui-form-item mart20">
                        <label class="layui-form-label w90">封面：</label>
                        <div class="layui-input-block cy-uploadpic-ctn" id="photo" style=" float:left;margin-left:0!important;position:relative;"></div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block" style="margin-left: 0px !important;text-align: center">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="releaseBtn">发布</button>
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">保存</button>
                <button type="button" id="cancel" class="layui-btn layui-btn-primary">取消</button>
                <button type="button" style="display: none;" id="save" class="layui-btn layui-btn-primary"></button>
            </div>
        </div>
    </form>
</div>
<script src="${s.base}/lib/layui/layui.js" type="text/javascript" charset="utf-8"></script>
<script src="${s.base}/js/common.js" type="text/javascript" charset="utf-8"></script>
<script src="${s.base}/lib/KnifeZ/ace/ace.js" type="text/javascript" charset="utf-8"></script>
<script>
    layui.use(['jquery', 'form', 'page', 'layedit', 'fileUtil', 'baseutil'], function () {
        var $ = layui.jquery,
            form = layui.form,
            page = layui.page,
            layedit = layui.layedit,
            fileUtil = layui.fileUtil,
            baseutil = layui.baseutil;

        //初始化附件控件
        fileUtil.uploadImage('photo', "work/site/mult", '${notice.photo}');
        //初始化富文本
        var index = baseutil.layeditKnifezBuild("content", 300);

        form.verify({
            content: function () {
                layedit.sync(index);
                if (isBlank($('#content').val())) {
                    return '请输入内容';
                }
            }
        });

        page.initDict('noticeType', function (dictData) {
            page.showDict($("#noticeType"), page.aceeptDictContentList(dictData, 'noticeType'), "请选择", '${notice.noticeType}');
        });

        //监听发布
        form.on('submit(releaseBtn)', function (data) {
            data.field.id = '${notice.id}';
            data.field.content = baseutil.layeditBuildContent(index);
            data.field.status = '1';
            baseutil.AjaxPostMark("/work/site/notice/addOrUpdate", data.field, function () {
                $("#save").click();
            });
            return false;
        });

        //监听保存
        form.on('submit(saveBtn)', function (data) {
            data.field.id = '${notice.id}';
            data.field.content = baseutil.layeditBuildContent(index);
            data.field.status = '2';
            baseutil.AjaxPostMark("/work/site/notice/addOrUpdate", data.field, function () {
                $("#save").click();
            });
            return false;
        });
    });
</script>
</body>
</html>